package com.imau.service.impl;

import com.imau.dao.AccountDao;
import com.imau.service.AccountService;
import com.imau.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;

@Service
public class AccountServiceImpl implements AccountService {

    @Autowired
    private AccountDao accountDao;

    @Autowired
    private LogService logService;

    @Override
    public void transfer(String outName, String inName, Double money) throws IOException {

        try {
            accountDao.outMoney(outName,money);
            if(true)
            {
                throw  new IOException("转账异常");
            }

            accountDao.inMoney(inName,money);
        }  finally {
            logService.log(outName,inName,money);
        }

    }
}
